package org.batatasframework.logger;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import cn.bonoon.kernel.support.IOperator;
import cn.bonoon.kernel.support.entities.AbstractPersistable;
import cn.bonoon.kernel.support.entities.Persistable;

@MappedSuperclass
public abstract class AbstractAmendmentLog<E extends Persistable> extends AbstractPersistable{
	
	private static final long serialVersionUID = 3009310974254814969L;
	
	@ManyToOne
	@JoinColumn(name = "R_SOURCE_ID")
	private E source;
	
	@Column(name = "C_CONTENT", length = 3000)
	private String content;

	@Column(name = "C_OWNER")
	private long owner;
	
	@Column(name = "C_CREATORNAME", length = 50)
	private String creatorName;
	
	@Column(name = "C_CREATORID")
	private Long creatorId;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "C_CREATEAT", nullable = false)
	private Date createAt;

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public long getOwner() {
		return owner;
	}

	public void setOwner(long owner) {
		this.owner = owner;
	}

	public String getCreatorName() {
		return creatorName;
	}

	public void setCreatorName(String creatorName) {
		this.creatorName = creatorName;
	}

	public Long getCreatorId() {
		return creatorId;
	}

	public void setCreatorId(Long creatorId) {
		this.creatorId = creatorId;
	}

	public Date getCreateAt() {
		return createAt;
	}

	public void setCreateAt(Date createAt) {
		this.createAt = createAt;
	}
	public void operator(IOperator operator){
		this.owner = operator.getOwnerId();
		this.creatorId = operator.getId();
		this.creatorName = operator.getUsername();
		this.createAt = new Date();
	}

	public E getSource() {
		return source;
	}

	public void setSource(E source) {
		this.source = source;
	}
	
}
